package Lobby;

import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class jGameRoom extends JPanel implements Runnable {
	//private volatile boolean finished = false;
	private Game Game;
	private ArrayList<PlayerInGame> PlayerInGameList;
	private JLabel lblPlayers;
	private JLabel lblPlayerNumbers;
	private JLabel lblPoints;
	private JButton btnJoin;
	
	jGameRoom(Game Game) {
		super();
		this.Game=Game;
		this.PlayerInGameList = Game.getPlayerInGameList();
		this.add(lblPlayers);
		this.add(lblPlayerNumbers);
		this.add(lblPoints);
		this.add(btnJoin);
		new Thread(this).start();
	}
	
	public void run() {
		while(Game.getGameState()==GameState.waitingForPlayers) {
			updateLabels();
			try {
			Thread.sleep(1000);
			}
			catch (Exception e) {
				break;
			}
		}
		this.setVisible(false);
		this.repaint();
		
	}
	private void updateLabels() {
		lblPlayers.setText(PlayerInGameList.toString());
		lblPlayerNumbers.setText(PlayerInGameList.size()+"/"+Game.getPlayerNumber());
	}
}
